package com.examples.progressbar;

import java.util.Random;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

public class ProgressBarBasic {

	public static void main(String[] args) {
		final Display d = Display.getDefault();
		Shell s = new Shell(d);

		final ProgressBar pb = new ProgressBar(s, SWT.HORIZONTAL | SWT.SMOOTH);
		pb.setMinimum(0);
		pb.setMaximum(100);		
		pb.setBounds(10, 10, 200, 20);

		d.timerExec(1000, new Runnable() {
			
			@Override
			public void run() {
				int v = pb.getSelection();
				Random random = new Random(System.currentTimeMillis());
				if (v < 100) {
					pb.setSelection(v + random.nextInt(15));
					if(!d.isDisposed()){
						d.timerExec(1000, this);
					}
				}				
			}
		});
		
		s.open();
		while (!s.isDisposed()) {
			if (!d.readAndDispatch())
				d.sleep();
		}
	}
}